﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.DAO;

public partial class Admin_ucControl_ListDVKH : System.Web.UI.UserControl
{
    DVKhachhangDAO dvkhDAO = new DVKhachhangDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadItems();

        }
    }
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int ItemID = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        Response.Redirect("~/Admin/ThemDVKH.aspx?id=" + ItemID);
    }
    protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        bool flag = false;
        try
        {
            int ItemID = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            dvkhDAO.DeleteItem(ItemID);
            flag = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
            Response.Redirect("~/Admin/DSKhachHang.aspx");
    }
    protected void grdItems_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                // check all cells in one row
                foreach (Control control in cell.Controls)
                {
                    ImageButton button = control as ImageButton;
                    if (button != null && button.CommandName == "Delete")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Bạn có thực sự muốn xoá sản phẩm này ?')) return false;";
                    }
                    if (button != null && button.CommandName == "Save")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Bạn có muốn lưu sản phẩm này ?')) return false;";
                    }
                }
            }
        }
    }
    protected void grdItems_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdItems.PageIndex = e.NewPageIndex;
        LoadItems();
    }

    private void LoadItems()
    {
        grdItems.DataSource = dvkhDAO.GetDVKH_All();
        grdItems.DataBind();
    }
}